
setClass("BrainHeader",
         representation(headerFile="character",
                        dataFile="character",
                        fileType="character",
                        versionNum="character",
                        encoding="character",
                        endian="character",
                        voxelOffset="numeric",
                        dataType="character",
                        info="list"),
         contains="VIRTUAL")


setClass("NIFTIHeader", contains="BrainHeader")

setClass("BrainFile",   representation(header="BrainHeader", "VIRTUAL"))

setClass("AnalyzeFile", contains="BrainFile")
setClass("NIFTIFile",   contains="BrainFile")
setClass("AFNIFile",    contains="BrainFile")



setClass("BrainSpace",
    representation(Dim = "integer", origin = "numeric", spacing = "numeric",
                   orientation="character", trans="matrix", invTrans="matrix"),
    prototype(Dim = as.integer(c(1,1,1)), origin=c(0,0,0), spacing=c(2,2,2),
              orientation=c("L", "P", "I"), trans=diag(1, 4), invTrans=diag(1,4)),
    validity = function(object) {
      Dim <- object@Dim
      if (length(Dim) != length(object@spacing)) {
        return("Dim slot must be of same length as spacing slot")
      }
      if (length(Dim) != length(object@origin)) {
        return("Dim slot must be of same length as origin slot")
      }
      if (length(Dim) != length(object@orientation)) {
        return("Dim slot must be of same length as orientation slot")
      }
      
      if (any(Dim) < 0) {
        return("Dim slot must contain non-negative values")
      }
    })
         



setClass("BrainData",
    representation(space="BrainSpace", "VIRTUAL"))


setClass("BrainSlice",
         contains="BrainData", "array")
         
setClass("BrainVolume", contains="BrainSlice")

setClass("BrainVector", contains="BrainVolume")

setClassUnion("index", members =  c("numeric", "logical", "character"))

## "atomic vectors" (-> ?is.atomic ) --
## ---------------  those that we want to convert from old-style "matrix"
setClassUnion("atomicVector", ## numeric = {integer, double} but all 3 should *directly* be atomic
	      members = c("logical", "integer", "double", "numeric",
			  "complex", "raw", "character"))
